<?php
/**
 * This page handles the creation of new users, using AJAX Quite heavily.
 * Found at /add/user
 * 
 * This page can only be accessed using mod_rewrite.
 */

    require_once('../SiteIncludes.GLOBAL.php');
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	$gVAR['e'] = '404';
	require_once('error_handler.php');
    }
    
    if(isset($_LOGGEDINUSER) === true && $_LOGGEDINUSER !== false) {
	$TemplateEngine->setHasSidebar(false);
	$TemplateEngine->create_content_html($Templater->makeherounit('XP :: Woops!', 'You are already logged in.', '<a class="btn btn-primary btn-large" href="/">Home Page</a>'));
    } else {
	/************************************************************************
	 * 
	 *	    Login Page
	 * 
	 ************************************************************************/
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/EMDE.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ajaxConfirmer.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/ToolTip.js"></script>');
	$TemplateEngine->add_postloadScript('<script type="text/javascript" src="/js/login.js"></script>');
	
	$TemplateEngine->setHasSidebar(false);
	$TemplateEngine->setCentralContentFullWidth(false);
	$loginbox = <<<EOLOGIN
	    <div id="signup_wait" style="margin-left: auto; margin-right: auto; text-align: center;" class="hiddenElement">
		<div class="span12" style="text-align: center;"><img src="/img/spin.gif" style="height: 32px; width: 32px;" id="signup_wait" /></div>
	    </div>
	    <div id="signup_form" style="margin-left: auto; margin-right: auto;">
		<iframe id="x_frame_user_add" name="x_frame_login" class="hiddenElement"></iframe>
		<form action="/edjx/login" method="POST" target="x_frame_login" id="x_frame_loginform">
		    <div class="row-fluid" id="check_container">
			<div class="span5" style="text-align: right;"><h2>&nbsp;Username&nbsp;:</h2></div>
			<div class="span4" style="text-align: left;">
			    <input type="text" name="ib_text_username" id="ib_text_username" onkeypress="login.keydown(event);" />
			</div>
			<div class="span3" style="text-align: left;"></div>
		    </div>
		    <div class="row-fluid" id="pass_container">
			<div class="span5" style="text-align: right;"><h2>&nbsp;Password&nbsp;:</h2></div>
			<div class="span4" style="text-align: left;">
			    <input type="password" name="ib_text_password" id="ib_text_password" onkeypress="login.keydown(event);" />
			</div>
			<div class="span3" style="text-align: left;"></div>
		    </div>
		    <div class="row-fluid" id="subm_container">
			<div class="span4" style="text-align: right;">&nbsp;</div>
			<div class="span5" style="text-align: center;">
			    <button type="button" onclick="login.SubmitClick();">Login</button>
			</div>
			<div class="span3">&nbsp;</div>
		    </div>
		    <div class="row-fluid" id="feedback_container">
			<div class="span4" style="text-align: right;">&nbsp;</div>
			<div class="span5" style="text-align: center;">
			    <span class="errorStyle hiddenElement" id="feedback_submit">Error</span>
			</div>
			<div class="span3">&nbsp;</div>
		    </div>
		</form>
	    </div>
EOLOGIN;
	$TemplateEngine->create_content_html($loginbox);
    }
    
    $TemplateEngine->render();
?>